public class testwork1 {
    public ListNode middleNode(ListNode head) {
        ListNode fast=head;
        ListNode slow=head;
        while(fast!=null&&fast.next!=null){//fast写全面防止fast.next空指针异常
            fast=fast.next.next;
            slow=slow.next;
        }
        return slow;
       /* int count=0;  // 方法二使用循环
        ListNode temp=head;
        while(temp!=null){
            count++;
            temp=temp.next;
        }
        int sum=count/2;
        while(sum!=0){
            head=head.next;
            sum--;
        }
        return head;*/
    }
}
